import 'package:casdon/common/utils/string_externtion.dart';
import 'package:casdon/modules/recipe/data/api/cook_module_content_api.dart';
import 'package:casdon/modules/recipe/data/model/recipe_placeholder_data.dart';
import 'package:casdon/modules/recipe/ui/widgets/Recipe_card_item.dart';

class CookModuleContentModel extends RecipeCardData {
  @override
  int get sort => 0;
  final String? _imgUrl; // 封面图
  final String? name; //
  @override
  final String? url; // 视频链接，
  final String id;

  final String view;
  final String collect;
  @override
  final String count;

  CookModuleContentModel({
    required String? imgUrl,
    required this.url,
    required this.name,

    required this.id,

    required this.view,
    required this.collect,
    required this.count,
  }) : _imgUrl = imgUrl;

  // 静态方法转换
  static CookModuleContentModel fromApi(CookModuleContent response) {
    return CookModuleContentModel(
      imgUrl: response.imageUrl,
      name: response.name ?? "",
      url: response.url,
      id: response.id,

      view: response.view ?? "0",
      collect: response.collect ?? "0",
      count: response.count ?? "0",
    );
  }

  // 批量转换的静态方法
  static List<CookModuleContentModel> listFromApi(
    List<CookModuleContent> items,
  ) {
    return items.map(fromApi).toList();
  }

  @override
  bool get isSmart => false;

  @override
  String get recipeId => id;

  @override
  String get imgUrl => (_imgUrl ?? recipePlaceHolderImgUrl).cropParams700;

  @override
  String get viewCount => view;

  @override
  String get title => name ?? "";

  @override
  RecipeCardData placeholder() {
    // TODO: implement placeholder
    throw UnimplementedError();
  }
}
